<template>
  <div class="login-form flex">
    <div class="login-con">
      <Row style="height: 100%">
        <Col
          :span="12"
          class="left-section flex flex-x-center flex-y-center"
          style="height: 100%"
        >
        <img
          src="@/assets/homePage/login-pic.png"
          alt=""
          style="width: 72.162%;"
        >
        </Col>
        <Col
          :span="12"
          class="flex flex-x-center flex-y-center"
          style="height: 100%"
        >
        <div class="form-con">
          <div class="mb60 flex flex-y-center flex-x-center">
            <img
              src="@/assets/homePage/logo.png"
              alt=""
              style="width: 45px;"
            >
            <span
              class="ml20 fontwBold"
              style="font-size: 34px;color: #1577FE;line-height: 48px;letter-spacing: 1px;"
            >淅川高智就业</span>
          </div>
          <!-- <Tabs value="扫码登录" @on-click="handleTabClick"> -->
          <!-- <TabPane label="扫码登录" name="扫码登录"> -->
          <!-- <div class="flex flex-y-center"> -->
          <!-- <img -->
          <!-- style="margin: 0 auto;width: 193px;" -->
          <!-- src="../../../../public/crmhotList/wxlogin.svg" -->
          <!-- alt="" -->
          <!-- /> -->
          <!-- </div> -->
          <!-- <div class="flex flex-y-center" style="text-align: center"> -->

          <!-- <a >
        <div class="logingo">
        企业微信登录
        </div>
      </a> -->

          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item
              label="用户名"
              prop="name"
            >
              <el-input v-model="ruleForm.name"></el-input>
            </el-form-item>
            <el-form-item
              label="密码"
              prop="pwd"
            >
              <el-input v-model="ruleForm.pwd"></el-input>
            </el-form-item>
            <el-form-item>
              <!-- <el-button :loading="loginLoading" type="primary" @click="submitForm('ruleForm')" >立即创建</el-button> -->
              <el-button
                :loading="loginLoading"
                type="primary"
                @click="wxSubmit('ruleForm')"
              >登 录</el-button>
              <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
            </el-form-item>
          </el-form>
          <!-- <Button
                    @click="wxSubmit"
                    type="primary"
                    long
                    :loading="loginLoading"
                    style="margin-top: 60px"
                    class="loginBtn"
                  >企业微信扫码登录
                  </Button
                  > -->
          <!-- </div> -->
          <!--            <div class="mt25">
                              <span>还未开通？</span>
                              &lt;!&ndash; <a @click="gowx" style="color: #3087fb">现在去授权</a> &ndash;&gt;
                              <router-link to="/register">现在去授权</router-link>
                            </div>-->
          <!-- </TabPane> -->
          <!--              <TabPane label="密码登录" name="密码登录">
                <Form
                  ref="formValidate"
                  :model="formValidate"
                  :rules="rules"
                  @keydown.enter.native="handleSubmit"
                >
                  <FormItem prop="userName" class="mb40">
                    <Input
                      v-model="formValidate.userName"
                      clearable
                      placeholder="请输入手机号"
                      prefix="ios-contact"
                    />
                    <span slot="prepend">
                  <Icon type="ios-contacts"/>
                </span>
                  </FormItem>
                  <FormItem prop="password" id="fromDiv1">
                    <Input
                      type="password"
                      v-model="formValidate.password"
                      password
                      placeholder="请输入密码"
                      prefix="md-lock"
                    />
                    <span slot="prepend">
                  <Icon :size="14" type="md-lock"></Icon>
                </span>
                  </FormItem>
                  <FormItem id="fromDiv">
                <span class="mt8">
                  <Checkbox v-model="single">记住账号 </Checkbox></span
                >
                    &lt;!&ndash;                    <span class="mt8">
                                      <span>
                                        <router-link style="color: #999999" to="/findpassword">忘记密码？</router-link> </span><span>
                    &lt;!&ndash;                    <router-link to="/register"> 去注册></router-link>&ndash;&gt;
                                      </span>
                                    </span>&ndash;&gt;
                  </FormItem>
                  <FormItem
                  >
                    <Button
                      @click="handleSubmit"
                      :loading="loginLoading"
                      type="primary"
                      long
                      class="loginBtn"
                    >登录
                    </Button
                    >
                  </FormItem
                  >
                </Form>
              </TabPane>-->
          <!-- <TabPane label="验证码登录" name="name2"> <SmsLogin></SmsLogin></TabPane> -->
          <!-- </Tabs> -->
        </div>
        </Col>
      </Row>
    </div>
  </div>
</template>
<script>
// import { codeLogin } from '../../../../../libs/jss/axios'
import { mapActions } from "vuex";
import tool from "@/libs/jss/FormValidation";
import service from "@/libs/service.js";
import { userLogin, getRouter } from '@/api/data.js'

export default {
  data () {
    return {
      ruleForm: {
        name: '15600089838',
        pwd: '123456',
      },
      rules: {
        name: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 11, max: 11, message: '请输入正确的手机号', trigger: 'blur' }
        ],
        pwd: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ],
        userName: [
          {
            required: true,
            validator: tool.FormValidate.Form().phone,
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" },
        ],
      },
      formValidate: { userName: "", password: "" },
      loginLoading: false,
      single: true,
      authCode: "",
      preAuthCode: "",
      expiresIn: "",
      state: "",
    };
  },
  props: {
    //控制是否弹出
    gologin: {
      type: Boolean,
      default: false,
    },
  },
  watch: {
    gologin (res) {
      if (res) {
        this.$Spin.hide();
      }
    },
  },
  computed: {},
  created () {
    console.log(process.env.NODE_ENV);
    // // auth_code如果存在的情况下，代表是由企业微信跳转过来的
    // if(this.$route.query.auth_code&&this.$route.query.expires_in&&this.$route.query.state){
    //   this.$emit('wxacthCode',{
    // preAuthCode:this.$route.query.auth_code,
    // expiresIn:this.$route.query.expires_in,
    // state:this.$route.query.state
    //   })
    // }
    // if (this.$route.query.auth_code) {
    //   this.$emit("wx-code-success-valid", {
    //     authCode: this.$route.query.auth_code,
    //   });
    // }
    // this.SubmitLogin();
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm (formName) {
      this.$refs[formName].resetFields();
    },
    ...mapActions([
      "handleLogin",
      "getUserInfo",
      "handlegoLogin",
      "wxAuthlogin",
    ]),
    homePage () {
      // this.$router.push('homePage')
    },
    SubmitLogin () {
      let url = location.search; //获取url中"?"符后的字串
      if (url) {
        let urls = url.split("?");
        let theRequest = urls[1].split("#");
        this.authCode = theRequest[0].split("&");
        this.authCode.forEach((item) => {
          if (item.indexOf("auth_code=" || "code") === 0) {
            this.preAuthCode = item.split("=")[1];
          }
          if (item.indexOf("state=") === 0) {
            this.state = item.split("=")[1];
          }
          if (item.indexOf("expires_in=") === 0) {
            this.expiresIn = item.split("=")[1];
          }
        });
        if (this.preAuthCode && this.state && this.expiresIn) {
          this.wxAuthlogin({
            preAuthCode: this.preAuthCode,
            expiresIn: this.expiresIn,
            state: this.state,
          })
            .then((resLogin) => {
              if (resLogin.code === 20000) {
                this.$Message.success("授权添加应用成功");
                localStorage.setItem(
                  "ifaccountyesnoQYWX",
                  resLogin.data.thirdType
                );
                this.$store.commit("print/setPrint", {
                  //print 表示vuex的文件名
                  ifaccountyesnoQYWX:
                    localStorage.getItem("ifaccountyesnoQYWX"),
                });
                this.getUserInfo(resLogin)
                  .then((res) => {
                    // 获取角色路由
                    this.APIS.getMenuList()
                      .then((res) => {
                        // service.routerRes(res.data);
                        console.log('qq', res.data);
                        this.$router.replace({
                          name: this.$config.homeName,
                        });
                        localStorage.setItem("menus", this.$config.homeName);
                        this.loginLoading = false;
                      })
                      .catch((err) => {
                        this.loginLoading = false;
                        removeToken();
                        console.log(err);
                      });
                  })
                  .catch(() => {
                    this.loginLoading = false;
                  });
              } else {
                this.loginLoading = false;
              }
            })
            .catch(() => {
              this.loginLoading = false;
              // this.$router.push({
              //   name: this.$config.homeName
              // })
            });
        } else if (this.preAuthCode) {
          this.handlegoLogin({
            authCode: this.preAuthCode,
          })
            .then((resLogin) => {
              if (resLogin.code === 20000) {
                localStorage.setItem(
                  "ifaccountyesnoQYWX",
                  resLogin.data.thirdType
                );
                this.$store.commit("print/setPrint", {
                  //print 表示vuex的文件名
                  ifaccountyesnoQYWX:
                    localStorage.getItem("ifaccountyesnoQYWX"),
                });
                this.getUserInfo(resLogin)
                  .then((res) => {
                    // 获取角色路由
                    this.APIS.getMenuList()
                      .then((res) => {
                        // service.routerRes(res.data);
                        this.$router.replace({
                          name: this.$config.homeName,
                        });
                        localStorage.setItem("menus", this.$config.homeName);
                        this.loginLoading = false;
                      })
                      .catch((err) => {
                        this.loginLoading = false;
                        removeToken();
                        console.log(err);
                      });
                  })
                  .catch(() => {
                    this.loginLoading = false;
                  });
              } else {
                this.loginLoading = false;
              }
            })
            .catch(() => {
              this.loginLoading = false;
              // this.$router.push({
              //   name: this.$config.homeName
              // })
            });
        }
      }
    },
    async handleSubmit () {
      //   this.$refs.formValidate.validate((valid) => {
      //     if (valid) {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          console.log('校验成功');
        } else {
          console.log('校验失败');
          return false;
        }
      })
      // this.$refs.ruleForm.validate(async valid => {
      //   if (valid) {
      //     const res = await Logo({
      //       phone: this.ruleForm.name,
      //       password: this.ruleForm.pwd
      //     })
      //     console.log('登录', res);
      //   } else {
      //     this.$Message.error('账号或密码错误');
      //   }
      // })

      // this.APIS.roleslist({}).then((res) => {

      //   this.rolesList = res.data
      // })

      this.loginLoading = true;
      let logData = {
        userPhone: this.formValidate.userName,
        userPassword: this.formValidate.password,
        platformCode: "ym_scrm",
      };
      /*this.APIS.getRouter({ sd: 1 }).then((routerRes) => {
        service.routerRes(routerRes.data);
        this.$router.replace({
          name: this.$config.homeName,
        });
      });*/
      this.handleLogin({
        userPhone: this.formValidate.userName,
        userPassword: this.formValidate.password,
        platformCode: "ym_scrm",
      })
        .then((resLogin) => {
          resLogin = {
            userName: '张三',
            token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6IuWRqOaYjOS4viIsImV4cCI6MTY4MTg4NTAzMSwidXNlcklkIjoiMTAifQ.XN01fJ7ox9-xNEFqVzHPXuHtlog-HDJM43PqQ3_aNcM',
            deptName: '淅川县',
            code: 20000
          }
          console.log('resLogin', resLogin);
          // service.routerRes([{ "id": 1, "parentId": 0, "path": "/home", "name": "home", "component": "Main", "menuType": 0, "permsType": "1", "sortNo": 1.0, "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "工作台" }, "children": [{ "id": 29, "parentId": 1, "path": "/yibao", "name": "yibao", "component": "yibaotongji", "menuType": 1, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "医保统计" }, "children": [] }, { "id": 30, "parentId": 1, "path": "/shebao", "name": "shebao", "component": "shebaotongji", "menuType": 1, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "社保统计" }, "children": [] }, { "id": 125, "parentId": 1, "path": "/yibaotongjitu", "name": "yibaotongjitu", "component": "yibaoyuanxingtu", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "医保圆形图" }, "children": [] }, { "id": 126, "parentId": 1, "path": "/shebaotongjitu", "name": "shebaotongjitu", "component": "shebaoyuanxingtu", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "社保圆形图" }, "children": [] }, { "id": 191, "parentId": 1, "path": "/yibaozhexiantu", "name": "yibaozhexiantu", "component": "yibaozhexiantu", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "医保折线图" }, "children": [] }, { "id": 192, "parentId": 1, "path": "/shebaozhexiantu", "name": "shebaozhexiantu", "component": "shebaozhexiantu", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "社保折线图" }, "children": [] }] }, { "id": 2, "parentId": 0, "path": "/peopleManagement", "name": "peopleManagement", "component": "Main", "menuType": 0, "permsType": "1", "sortNo": 2.0, "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "缴费信息" }, "children": [{ "id": 56, "parentId": 2, "path": "/yibaoorder", "name": "yibaoorder", "component": "yibaodingdan", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "医保订单" }, "children": [{ "id": 80, "parentId": 56, "path": "/shebaochakan", "name": "shebaochakan", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "查看" }, "children": [] }, { "id": 81, "parentId": 56, "path": "/shebaotuikuan", "name": "shebaotuikuan", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "退款" }, "children": [] }] }, { "id": 57, "parentId": 2, "path": "/shebaoorder", "name": "shebaoorder", "component": "shebaodingdan", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "社保订单" }, "children": [{ "id": 82, "parentId": 57, "path": "/yibaochakan", "name": "yibaochakan", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "查看" }, "children": [] }, { "id": 83, "parentId": 57, "path": "/yibaotuikuan", "name": "yibaotuikuan", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "退款" }, "children": [] }] }] }, { "id": 3, "parentId": 0, "path": "/residentManagement", "name": "residentManagement", "component": "Main", "menuType": 0, "permsType": "1", "sortNo": 3.0, "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "未缴费人员" }, "children": [{ "id": 72, "parentId": 3, "path": "/weijiaofeiyibaolist", "name": "weijiaofeiyibaolist", "component": "yibao", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "医保" }, "children": [{ "id": 88, "parentId": 72, "path": "/weijiaofeiyibaochakan", "name": "weijiaofeiyibaochakan", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "查看" }, "children": [] }, { "id": 89, "parentId": 72, "path": "/weijianfeiyibaobianji", "name": "weijianfeiyibaobianji", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "编辑" }, "children": [] }, { "id": 208, "parentId": 72, "path": "/weijiaofeiyibaodaochu", "name": "weijiaofeiyibaodaochu", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "导出数据" }, "children": [] }] }, { "id": 73, "parentId": 3, "path": "/weijiaofeishebaolist", "name": "weijiaofeishebaolist", "component": "shebao", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "社保" }, "children": [{ "id": 86, "parentId": 73, "path": "/weijiaofeishebaochakan", "name": "weijiaofeishebaochakan", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "查看" }, "children": [] }, { "id": 87, "parentId": 73, "path": "/weijiaofeishebaobianji", "name": "weijiaofeishebaobianji", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "编辑" }, "children": [] }, { "id": 207, "parentId": 73, "path": "/weijiaofeishebaodaochu", "name": "weijiaofeishebaodaochu", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "导出数据" }, "children": [] }] }] }, { "id": 4, "parentId": 0, "path": "/loginPeople", "name": "loginPeople", "component": "Main", "menuType": 0, "permsType": "1", "sortNo": 4.0, "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "统计分析" }, "children": [{ "id": 188, "parentId": 4, "path": "/fenxiyibao", "name": "fenxiyibao", "component": "fenxiyibao", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "医保" }, "children": [] }, { "id": 189, "parentId": 4, "path": "/fenxishebao", "name": "fenxishebao", "component": "fenxishebao", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "社保" }, "children": [] }] }, { "id": 5, "parentId": 0, "path": "/authorityManagement", "name": "authorityManagement", "component": "Main", "menuType": 0, "permsType": "1", "sortNo": 5.0, "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "参保人员" }, "children": [{ "id": 8, "parentId": 5, "path": "/juMinLieBiao", "name": "juMinLieBiao", "component": "canbaorenyuan", "menuType": 1, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "参保人员" }, "children": [{ "id": 11, "parentId": 8, "path": "/xinZeng", "name": "xinZeng", "component": "button_top", "menuType": 3, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "新增居民" }, "children": [] }, { "id": 12, "parentId": 8, "path": "/xiangQing", "name": "xiangQing", "component": "button", "menuType": 3, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "查看" }, "children": [] }, { "id": 13, "parentId": 8, "path": "/xiuGai", "name": "xiuGai", "component": "button", "menuType": 3, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "编辑" }, "children": [] }, { "id": 14, "parentId": 8, "path": "/daoRu", "name": "daoRu", "component": "button_top", "menuType": 3, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "导入数据" }, "children": [] }, { "id": 15, "parentId": 8, "path": "/shanChu", "name": "shanChu", "component": "button", "menuType": 3, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "删除" }, "children": [] }, { "id": 97, "parentId": 8, "path": "/daochushuju", "name": "daochushuju", "component": "button_top", "menuType": 3, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "导出数据" }, "children": [] }, { "id": 205, "parentId": 8, "path": "/quickjianyuan", "name": "quickjianyuan", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "减员" }, "children": [] }, { "id": 206, "parentId": 8, "path": "/quickzhengce", "name": "quickzhengce", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "享受政策" }, "children": [] }] }, { "id": 9, "parentId": 5, "path": "/zengYuanLieBiao", "name": "zengYuanLieBiao", "component": "zengyuan", "menuType": 1, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "增员" }, "children": [{ "id": 62, "parentId": 9, "path": "/zengyuan", "name": "zengyuan", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "增员" }, "children": [] }, { "id": 63, "parentId": 9, "path": "/daoru", "name": "daoru", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "导入数据" }, "children": [] }, { "id": 64, "parentId": 9, "path": "/chakan", "name": "chakan", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "查看" }, "children": [] }, { "id": 92, "parentId": 9, "path": "/shenpi", "name": "shenpi", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "审批" }, "children": [] }, { "id": 200, "parentId": 9, "path": "/daochushuju", "name": "daochushuju", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "导出数据" }, "children": [] }, { "id": 202, "parentId": 9, "path": "/bianji", "name": "bianji", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "重新提交" }, "children": [] }] }, { "id": 10, "parentId": 5, "path": "/jianYuanLieBiao", "name": "jianYuanLieBiao", "component": "jianyuan", "menuType": 1, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "减员" }, "children": [{ "id": 65, "parentId": 10, "path": "/xinzeng", "name": "xinzeng", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "减员" }, "children": [] }, { "id": 66, "parentId": 10, "path": "/daoru", "name": "daoru", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "导入数据" }, "children": [] }, { "id": 67, "parentId": 10, "path": "/xiangqing", "name": "xiangqing", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "查看" }, "children": [] }, { "id": 94, "parentId": 10, "path": "/jianyuanshenpi", "name": "jianyuanshenpi", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "审批" }, "children": [] }, { "id": 100, "parentId": 10, "path": "/daochushuju", "name": "daochushuju", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "导出数据" }, "children": [] }, { "id": 203, "parentId": 10, "path": "/bianji", "name": "bianji", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "重新提交" }, "children": [] }] }, { "id": 23, "parentId": 5, "path": "/xiangShouZhengCe", "name": "xiangShouZhengCe", "component": "xiangshouzhengcerenyuan", "menuType": 1, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "享受政策人员" }, "children": [{ "id": 95, "parentId": 23, "path": "/chakan", "name": "chakan", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "查看" }, "children": [] }, { "id": 102, "parentId": 23, "path": "/zhengceshenpitongguo", "name": "zhengceshenpitongguo", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "审批" }, "children": [] }, { "id": 103, "parentId": 23, "path": "/xinzeng", "name": "xinzeng", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "新增" }, "children": [] }, { "id": 104, "parentId": 23, "path": "/daorushuju", "name": "daorushuju", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "导入数据" }, "children": [] }, { "id": 105, "parentId": 23, "path": "/daochushuju", "name": "daochushuju", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "导出数据" }, "children": [] }, { "id": 204, "parentId": 23, "path": "/bianji", "name": "bianji", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "重新提交" }, "children": [] }] }] }, { "id": 6, "parentId": 0, "path": "/zhengceguanli", "name": "zhengceguanli", "component": "Main", "menuType": 0, "permsType": "1", "sortNo": 6.0, "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "政策管理" }, "children": [{ "id": 106, "parentId": 6, "path": "/zhengce", "name": "zhengce", "component": "zhengce", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "政策" }, "children": [{ "id": 16, "parentId": 106, "path": "/xinzengzhengce", "name": "xinzengzhengce", "component": "button_top", "menuType": 3, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "新增政策" }, "children": [] }, { "id": 17, "parentId": 106, "path": "/chakan", "name": "chakan", "component": "button", "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "查看" }, "children": [] }, { "id": 18, "parentId": 106, "path": "/bianji", "name": "bianji", "component": "button", "menuType": 3, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "编辑" }, "children": [] }, { "id": 28, "parentId": 106, "path": "/shanchu", "name": "shanchu", "component": "button", "menuType": 3, "permsType": "1", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "删除" }, "children": [] }, { "id": 108, "parentId": 106, "path": "/piliangshanchu", "name": "piliangshanchu", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "批量删除" }, "children": [] }] }, { "id": 107, "parentId": 6, "path": "/bangzhu", "name": "bangzhu", "component": "bangzhu", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "帮助" }, "children": [{ "id": 109, "parentId": 107, "path": "/xinjianbangzhu", "name": "xinjianbangzhu", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "新建帮助" }, "children": [] }, { "id": 110, "parentId": 107, "path": "/piliangshanchu", "name": "piliangshanchu", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "批量删除" }, "children": [] }, { "id": 111, "parentId": 107, "path": "/bianji", "name": "bianji", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "编辑" }, "children": [] }, { "id": 112, "parentId": 107, "path": "/shanchu", "name": "shanchu", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "删除" }, "children": [] }] }] }, { "id": 7, "parentId": 0, "path": "/xitongshezhi", "name": "xitongshezhi", "component": "Main", "menuType": 0, "permsType": "1", "sortNo": 7.0, "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "系统设置" }, "children": [{ "id": 22, "parentId": 7, "path": "/biaoqianshezhi", "name": "biaoqianshezhi", "component": "biaoqianshezhi", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "标签设置" }, "children": [{ "id": 120, "parentId": 22, "path": "/tianjiabiaoqianzu", "name": "tianjiabiaoqianzu", "component": "button_top", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "添加标签组" }, "children": [] }, { "id": 121, "parentId": 22, "path": "/bianji", "name": "bianji", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "编辑" }, "children": [] }, { "id": 122, "parentId": 22, "path": "/shanchu", "name": "shanchu", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "删除" }, "children": [] }] }, { "id": 49, "parentId": 7, "path": "/shenpiliucheng", "name": "shenpiliucheng", "component": "shenpiliucheng", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "审批流程" }, "children": [{ "id": 119, "parentId": 49, "path": "/baocun", "name": "baocun", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "保存" }, "children": [] }] }, { "id": 113, "parentId": 7, "path": "/jiaofeiguanli", "name": "jiaofeiguanli", "component": "jiaofeiguanli", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "缴费管理" }, "children": [{ "id": 184, "parentId": 113, "path": "/yibao", "name": "yibao", "component": "button_left", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "医保" }, "children": [{ "id": 124, "parentId": 184, "path": "/bianji", "name": "bianji", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "编辑" }, "children": [] }] }, { "id": 185, "parentId": 113, "path": "/shebao", "name": "shebao", "component": "button_left", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "社保" }, "children": [{ "id": 186, "parentId": 185, "path": "/bianji", "name": "bianji", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "编辑" }, "children": [] }] }] }, { "id": 114, "parentId": 7, "path": "/yonghuquanxian", "name": "yonghuquanxian", "component": "yonghuquanxian", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "用户权限" }, "children": [{ "id": 123, "parentId": 114, "path": "/baocun", "name": "baocun", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "保存" }, "children": [] }] }, { "id": 116, "parentId": 7, "path": "/tongxunlu", "name": "tongxunlu", "component": "tongxunlu", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "通讯录" }, "children": [{ "id": 31, "parentId": 116, "path": "/zuzhijiegou", "name": "zuzhijiegou", "component": "button_top", "menuType": 1, "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "同步企业微信通讯录" }, "children": [] }, { "id": 117, "parentId": 116, "path": "/bianji", "name": "bianji", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "角色管理" }, "children": [] }, { "id": 118, "parentId": 116, "path": "/quyuguanli", "name": "quyuguanli", "component": "button", "permsType": "0", "isRoute": 1, "ruleFlag": 0, "enabled": 1, "meta": { "hideInMenu": false, "title": "区域管理" }, "children": [] }] }] }])
          this.$router.replace(
            {
              name: 'home'
            }
          )
          if (resLogin.code === 20000) {
            localStorage.setItem(
              "ifaccountyesnoQYWX",
              resLogin.data.thirdType
            );
            this.$store.commit("print/setPrint", {
              //print 表示vuex的文件名
              ifaccountyesnoQYWX:
                localStorage.getItem("ifaccountyesnoQYWX"),
            });
            console.log(222);

            this.getUserInfo(resLogin)
              .then((res) => {
                // 获取角色路由
                console.log('getUserInfo', res);


                this.APIS.getMenuList()
                  .then((res) => {
                    console.log('找死啊', res);
                    // service.routerRes(res.data);
                    this.$router.replace({
                      // name: this.$config.homeName,
                      name: 'home',

                    });
                    // localStorage.setItem("menus", this.$config.homeName);
                    localStorage.setItem("menus", 'home');

                    this.loginLoading = false;
                  })
                  .catch((err) => {
                    this.loginLoading = false;
                    removeToken();
                    console.log(err);
                  });
              })
              .catch(() => {
                this.loginLoading = false;
              });
          } else {
            this.loginLoading = false;
          }
        })
        .catch(() => {
          this.loginLoading = false;
          // this.$router.push({
          //   name: this.$config.homeName
          // })
        });
      //   }
      // });
    },
    async gowx () {
      await this.APIS.wxAuth()
        .then((res) => {
          if (res.data) {
            window.location.href = res.data;
          }
        })
        .catch((err) => {
        });
    },
    getRouters() {

    },
    wxSubmit () {
      // const arr = [
      //         {
      //           path: 'home',
      //           name: 'home',
      //           component: 'home',
      //           children: [],
      //           meta: {
      //             hideInMenu: true,
      //             title: '工作台',
      //           },
      //         },
      //         {
      //           path: '/zhengceguanli',
      //           name: 'zhengceguanli',
      //           component: 'zhengceguanli',
      //           children: [],
      //           meta: {
      //             hideInMenu: true,
      //             title: '机构管理',
      //           },
      //         },
      //         {
      //           path: '/loginPeopl',
      //           name: 'loginPeopl',
      //           component: 'loginPeopl',
      //           children: [],
      //           meta: {
      //             hideInMenu: true,
      //             title: '风采展示',
      //           },
      //         },
      //         {
      //           path: '/residentManagement',
      //           name: 'residentManagement',
      //           component: 'residentManagement',
      //           children: [],
      //           meta: {
      //             hideInMenu: true,
      //             title: '招聘管理',
      //           },
      //         },
      //         {
      //           path: '/peopleManagement',
      //           name: 'peopleManagement',
      //           component: 'peopleManagement',
      //           children: [],
      //           meta: {
      //             hideInMenu: true,
      //             title: '就业人员',
      //           },
      //         }
      //       ]
            
      this.$refs.ruleForm.validate(async valid => {
        if (valid) {
          const res = await userLogin({
            phone: this.ruleForm.name,
            password: this.ruleForm.pwd
          })
          console.log('登录', res);
          localStorage.setItem('token', res.token)
          this.$Message.success('登入成功')
          const token = localStorage.getItem('token')
          if (token) {
            const res = await getRouter({
              token
            })
            console.log('路由信息', res);
            console.log('点击');
            localStorage.setItem('routers', res)
            service.routerRes(res)
            this.$store.commit('setRouter', res)
            this.$store.commit('setUser', res)
            const a = JSON.parse(localStorage.getItem('routerList'))
            this.$store.commit('headersToken', 'token')
            this.handleSubmit();
            
            if (this.$store.state.user.routerList.length > 5) {
              
            }
          }
        }
        // } else {
        //   this.$Message.error('账号或密码错误');
        // }
      })
      if (process.env.NODE_ENV === "development") {
        
      } else if (process.env.NODE_ENV === "prerelease") {
        window.location.href =
          "https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=ww1add0f813968d635&agentid=1000066&redirect_uri=https%3A%2F%2Fpreshoufei.yzxsaas.com%2Fpc%2F%23%2Flogin&state=STATE";
      } else if (process.env.NODE_ENV === "production") {
        window.location.href =
          "https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=ww1add0f813968d635&agentid=1000066&redirect_uri=https%3A%2F%2Fpreshoufei.yzxsaas.com%2Fpc%2F%23%2Flogin&state=STATE";
      }
      
    },
    handleTabClick (val) {
      if (val === "二维码登录") {
      }
    },
  },
};
</script>

<style lang="less" scoped>
@import "../login.less";
</style>
